package com.foreveross.taskservice.web.listener;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.context.support.WebApplicationContextUtils;

import com.foreveross.taskservice.infra.cfg.ConfigLoader;
import com.foreveross.taskservice.infra.util.SpringUtil;


/**
 * 做一个自启动监听，主要是Quartz中无法做spring的注入操作。 在此类中加载InstanceFactory和加载配置文件
 * 
 * @author Administrator
 * 
 */
public class InitListener implements ServletContextListener {
	private static Logger log = LoggerFactory.getLogger(InitListener.class);

	@Override
	public void contextDestroyed(ServletContextEvent arg0) {
		log.info("[任务服务结束]");
	}

	@Override
	public void contextInitialized(ServletContextEvent event) {
		log.info("[任务服务启动]");
		ConfigLoader.initLoader();
		SpringUtil.ctx =  WebApplicationContextUtils.getWebApplicationContext(event.getServletContext());
	}
}
